//
//  Common.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/1/29.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit
import SnapKit
import Kingfisher
import PKHUD

/// 导航栏高度
let NavigationHeight: CGFloat = 64
/// tabbar 高度
let BarHeight: CGFloat = 49.0
/// 屏幕宽度
let ScreenWidth: CGFloat = UIScreen.main.bounds.size.width
/// 屏幕高度
let ScreenHeight: CGFloat = UIScreen.main.bounds.size.height
/// 圆角度
let CORNERRADIUS: CGFloat = 6.0
/// 动画时间
let anTIME: TimeInterval = 0.2
/// 底部阴影偏移量
let bottomShadowOffset = CGSize(width: 0, height: 5)
/// 阴影的透明度
let bottomShadowOpacity: CGFloat = 0.5
/// 基链接
//let BaseURL: String = "http://182.92.224.59:9981"
let BaseURL: String = "http://www.1du.me"
/// 登录
let loginUrl:String = "/miwebproj/api/auth/login"
/// 注销
let logoutUrl:String = "/miwebproj/api/auth/logout"
/// 注册
let registerUrl:String = "/miwebproj/api/auth/reg"
/// 获取验证码
let getCodeUrl:String = "/miwebproj/api/auth/sms"
/// 获取验证码
let verifyCodeUrl:String = "/miwebproj/api/auth/verify"
//获取用户信息
let getUserInfo:String = "/miwebproj/api/auth/info"
/// 修改用户资料
let updateUserInfoUrl:String = "/miwebproj/api/auth/alter"
/// 修改用户手机
let updateUserPhoneUrl:String = "/miwebproj/api/auth/altermp"
/// 解绑
let unBindUserUrl:String = "/miwebproj/api/auth/unbind"
/// 绑定
let bindUserUrl:String = "/miwebproj/api/auth/bind"
/// 获取兴趣标签
let interestMarkUrl:String = "/miwebproj/api/label/tree"
/// 重置密码，忘记密码
let resetPwdUrl:String = "/miwebproj/api/auth/resetpsw"
/// 修改密码
let updatePwdUrl:String = "/miwebproj/api/auth/alterpsw"
/// 首页文章列表
let homeArticleUrl:String = "/miwebproj/api/article"
/// 首页视频列表
let homeVideoUrl:String = "/miwebproj/api/video"
/// banner
let bannerUlr:String = "/miwebproj/api/general/banner"
/// 圈子
let circleUrl:String = "/miwebproj/api/circle/mgr/list"
/// 圈子
let userCircleUrl:String = "/miwebproj/api/circle/user/circlelist"
//圈子详情
let circleDetailUrl:String = "/miwebproj/api/circle/manage"
//圈子动态
let circleDetailTabUrl:String = "/miwebproj/api/circle/trends"
//加入圈子
let circleJoinUrl:String = "/miwebproj/api/circle/joincircle"
//退出圈子
let circleOutUrl:String = "/miwebproj/api/circle/exitcircle"
/// 购物车
let shoppingCartListUrl:String = "/miwebproj/api/purchaseGoodsInfos/listPurchaseGoodsInfos"
/// 购买列表
let shoppingListUrl:String = "/miwebproj/api/goodsAdmin"
/// 获取商品推荐列表
let recommendShoppingListUrl = "/miwebproj/api/goodsAdmin/listStickGoodsInfos"
/// 获取商品详情中文章推荐列表
let recommendContentListUrl = "/miwebproj/api/general/rec_contents_goods"
/// 获取搜索关键字
let searchKeyUrl = "/miwebproj/api/search/skey/recommand"
/// 获取搜索记录
let searchRecordUrl = "/miwebproj/api/search/skey/history"
/// 搜索圈子
let searchCircleUrl = "/miwebproj/api/search/circle"
/// 搜索商品
let searchGoodsUrl = "/miwebproj/api/search/goods"
/// 搜索视频
let searchVideoUrl = "/miwebproj/api/search/video"
/// 搜索文章
let searchArticleUrl = "/miwebproj/api/search/article"
/// 搜索用户
let searchUserUrl = "/miwebproj/api/search/user"
/// 搜索为你推荐
let searchRecommendUrl = "/miwebproj/api/search/recommand"
/// 清空历史搜索
let clearHistorySearchUrl = "/miwebproj/api/search/skey/remove"
/// 相关推荐内容
let recommendContentUrl = "/miwebproj/api/general/rec_contents"
/// 评论列表 资讯 和 视频的
let commentListUrl="/miwebproj/api/comments/list"

let relateCommentListUrl = "/miwebproj/api/comments/relatedcomments"
/// 发布评论 资讯 视频
let sendCommentUrl="/miwebproj/api/comments/save"

/// 关注用户
let attentionUserUrl = "/miwebproj/api/concern/add"
/// 取消关注用户
let attentionCancelUserUrl = "/miwebproj/api/concern/cancel"
/// 点赞 资讯 视频 商品
let commentLikeUrl = "/miwebproj/api/commentlikes/save"
/// 获取文章
let fetchArticleDetailURl = "/miwebproj/api/article"
/// 收藏文章|视频|会用|商品
let collectUrl = "/miwebproj/api/collect/add"
/// 取消收藏文章|视频|会用|商品
let cancelCollectUrl = "/miwebproj/api/collect/cancel"
/// 回复评论
let replyCommentUrl = "/miwebproj/api/comments/reply"
/// 举报列表
let jbListUrl = "/miwebproj/api/commentreport/rrList"
/// 获取视频
let fetchVideoUrl = "/miwebproj/api/video"
/// 上传文件
let uploadFileUrl = "/miwebproj/api/file"
/// 商品详情
let fetchGoodsDetailUrl = "/miwebproj/api/goodsAdmin/getGoodsInfos"
/// 商品评论列表
let goodsCommentListUrl = "/miwebproj/api/productcomments/list"
/// 收货地址列表
let addressListUrl = "/miwebproj/api/deliveryAddress/listDeliveryAddress"
/// 编辑收货地址
let addressEditUrl = "/miwebproj/api/deliveryAddress/editDeliveryAddress"
/// 删除收货地址
let addressDelUrl = "/miwebproj/api/deliveryAddress/delDeliveryAddress"
/// 获取收货地址
let addressInfoUrl = "/miwebproj/api/deliveryAddress/getDeliveryAddress"
/// 获取默认收货地址
let addressDefaultUrl = "/miwebproj/api/deliveryAddress/getDefaultDeliveryAddress"
/// 设置默认收货地址
let addressDefaultUrlSet = "/miwebproj/api/deliveryAddress/setDefaultAddress"
/// 发货地址重新计算运费及总价
let getPriceAndFee = "/miwebproj/api/purchaseAdmin/recomputeFee"
/// 城市地址列表
let ciyListUrl = "/miwebproj/api/deliveryAddress/provinceCity"

//用户内容
let myContentUrl = "/miwebproj/api/general/personal_publish"
//用户草稿
let myContentCGUrl = "/miwebproj/api/general/personal_draft"
//用户收藏
let myShoucangUrl = "/miwebproj/api/collect/list"
//我的订单
let myOrderUrl = "/miwebproj/api/purchaseAdmin/getPurchaseInfos"
//取消订单
let cancelOrderUrl = "/miwebproj/api/purchaseAdmin/cancelGoodsInfos"
//删除订单
let deleteOrderUrl = "/miwebproj/api/purchaseAdmin/delPurchaseInfos"
//我的订单列表
let myOrderListUrl = "/miwebproj/api/purchaseAdmin/listPurchageInfos"
//催单
let reminder = "/miwebproj/api/purchaseAdmin/reminder"
//确认收货
let confirmReceived = "/miwebproj/api/purchaseAdmin/confirmReceived"
//申请售后
let applyAfterService = "/miwebproj/api/purchaseAdmin/applyAfterService"
//取消售后
let cancelAfterService = "/miwebproj/api/purchaseAdmin/cancelAfterService"
//我的评论
let myCommenteUrl = "/miwebproj/api/comments/mymessage/comments"
//我的点赞
let myLikeUrl = "/miwebproj/api/commentlikes/list"
//我的消息
let myMessageUrl = "/miwebproj/api/comments/mymessage/sysmsg"
//圈子成员
let circleList = "/miwebproj/api/circle/userin/list"
//意见反馈
let feedBackUrl = "/miwebproj/api/feedback"
//用户加入的圈子
let circleJoinedUrl = "/miwebproj/api/circle/user/circlelist"
//获取用户信息
let userDetailUrl = "/miwebproj/api/general/userInfo"
//添加购物车
let addCartUrl = "/miwebproj/api/purchaseGoodsInfos/editPurchaseGoodsInfos"
//购物车列表
let cartListUrl = "/miwebproj/api/purchaseGoodsInfos/listPurchaseGoodsInfos"
//删除购物车
let delCar = "/miwebproj/api/purchaseGoodsInfos/delPurchaseGoodsInfos"
//立即购买
let payAtOnceUrl = "/miwebproj/api/purchaseGoodsInfos/prepurchase"
//再次购买
let purchaseAgain = "/miwebproj/api/purchaseAdmin/purchaseAgain"
//确认下单
let payNowUrl = "/miwebproj/api/purchaseAdmin/editPurchaseInfos"
//支付
let payUrl = "/miwebproj/api/onlinePay/prePay"
//粉丝
let folleowUrl = "/miwebproj/api/concern/follow"
let fansUrl = "/miwebproj/api/concern/fans"
//举报
let reportUrl = "/miwebproj/api/commentreport/save"
//评论商品
let commendGoodsUrl = "/miwebproj/api/productcomments/save"
//删除文件
let deleteFielUrl = "/miwebproj/api/file/del"
//删除文章
let deleteArticleUrl = "/miwebproj/api/article/del"
//删除视频
let deleteVideoUrl = "/miwebproj/api/video/del"
/// 最大请求数
let MAXRequestCount = 10
/// 行间距
let LinesSpacing: CGFloat = 7
/// 搜索历史文件名
let searchHplistName = "searchH.plist"
/// 持久化用户信息文件名
let userAccountSTR = "userAccount.data"

/// 适配IPX高度
struct Ipx {
    // IPX高度
    let IPXHEIGHT: CGFloat = 812
    
    var isHide = false
    
    init(_ isHide: Bool) {
        self.isHide = isHide
    }
    
    var bottomMargin: CGFloat {
        get{
            if ScreenHeight == IPXHEIGHT {
                return 34
            } else {
                return 0
            }
        }
    }
    
    var topMargin: CGFloat {
        get {
            if ScreenHeight == IPXHEIGHT {
                return isHide ? 44 : 24
            } else {
                return 0
            }
        }
    }
}

/// 按比屏幕例设置尺寸（目前以ip5为基准）
///
/// - Parameter r: 输入的尺寸
/// - Returns: 按比例返回的尺寸
func kHeight(r: CGFloat) -> CGFloat {
    let isIP5 = ScreenHeight == 568
    if isIP5 {
        return r
    } else {
        if ScreenHeight == Ipx(true).IPXHEIGHT {
            return 1.174 * r
        } else {
            return r * (ScreenHeight / 568)
        }
    }
}

func DEGREES_TO_RADIANS(x: Double) -> CGFloat{
    return CGFloat(x / 180.0 * .pi)
}

func appendUrl(suffix: String) -> URL{
    var path:String = "\(BaseURL)\(suffix)"
    path = path.addingPercentEncoding(withAllowedCharacters:
        .urlQueryAllowed)!
    let url:URL = URL(string:path)!
    return url
}

func string2Date(dateString: String) -> Date {
    let date = Date()
    let dateFormatter = DateFormatter()
    
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
    let dateTime = dateFormatter.date(from: dateString)
    return dateTime!
}

func date2String(dateString: Date) -> String {
    let date = Date()
    let dateFormatter = DateFormatter()
    
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
    let stringTime = dateFormatter.string(from: date)
    return stringTime
}

func time2Time(date: Date, another: Date) -> TimeInterval{
    var stamp: TimeInterval = another.timeIntervalSince(date)
   
    return stamp
}

func time2ShowTime(stamp: TimeInterval) -> String {
    let stamp0 = Int(stamp)
    let second: Int = Int(stamp0 % 60)
    let minute: Int = Int((stamp0 / 60) % 60)
    let hour: Int = Int((stamp0 / 3600) % 24)
    let day: Int = (Int(stamp0 / 3600 / 24))
    var hourStr = "\(hour)"
    if hour < 10 {
        hourStr = "0" + hourStr
    }
    var minuteStr = "\(minute)"
    if minute < 10 {
        minuteStr = "0" + minuteStr
    }
    var secondStr = "\(second)"
    if second < 10 {
        secondStr = "0" + secondStr
    }
    return hourStr + ":" + minuteStr + ":" + secondStr
}



